package com.teach.hotel;

import java.util.Scanner;

public class SystemConsole {

	private static Scanner in;

	public static void main(String[] args) {
		in = new Scanner(System.in);
		TestData.add();
		mainMenu();
	}

	public static void mainMenu() {
		System.out.println("-----------主菜单----------");
		System.out.println(" 0. 管理员");
		System.out.println(" 1. 前台");
		System.out.println("-------------------------");
		int menu = in.nextInt();
		if (menu == 0) {
			adminMenu();
		} else {
			playMenu();
		}
	}

	/**
	 * 主菜单
	 */
	public static void adminMenu() {
		System.out.println("-----------管理菜单----------");
		System.out.println(" 0. 返回主菜单");
		System.out.println(" 1. 房型价格管理");
		System.out.println(" 2. 房间管理");
		System.out.println("-------------------------");
		int menu = in.nextInt();
		switch (menu) {
		case 1:
			Type.menu();
			break;
		case 2:
			Room.menu();
			break;

		default:
			mainMenu();
			break;
		}
	}

	/**
	 * 前台菜单
	 */
	public static void playMenu() {
		System.out.println("-----------管理菜单----------");
		System.out.println(" 0. 返回主菜单");
		System.out.println(" 1. 查看空房");
		System.out.println(" 2. 入住");
		System.out.println(" 3. 退房");
		System.out.println(" 4. 查看入住清单");
		System.out.println("-------------------------");
		int menu = in.nextInt();
		switch (menu) {
		case 1:
			printEmptyNum();
			break;
		case 2:
			Record.inRoom();
			break;
		case 3:
			Record.outRoom();
			break;
		case 4:
			Record.lookAll();
			break;

		default:
			mainMenu();
			return;
		}
		playMenu();
	}

	/**
	 * 统计空房间数
	 */
	public static void printEmptyNum() {
		System.out.println("编号\t房型\t数量\t空房间数");
		for (int i = 0; i < Type.types.size(); i++) {
			Type t = Type.types.get(i);
			System.out.println(i + "\t" + t.getName() + "\t" + t.getList().size() + "\t" + countEmptyNum(t));
		}
	}

	public static int countEmptyNum(Type t) {
		int count = 0;
		for (Room r : t.getList()) {
			if (!r.getEnable()) {
				count++;
			}
		}
		return count;
	}



}
